﻿package mortal.game.view.lotteryDraw
{
    import Message.DB.Tables.*;
    import __AS3__.vec.*;
    import baseEngine.modifiers.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.geom.*;
    import frEngine.effectEditTool.temple.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.util.*;
    import mortal.mvc.interfaces.*;

    public class lotteryDrawAnjinSkillWin extends BaseWindow
    {
        private var _showItemVec:Vector.<BaseItem>;
        private var _bg:GImageBitmap;
        protected var _rect3d:Rect3DObject;
        private var _img2d:Img2D;
        private var _bodyPlayer:ActionPlayer;
        private var _effectPlayer:EffectPlayer;
        private var _equipNum:int = 8;
        private static var _instance:lotteryDrawAnjinSkillWin;

        public function lotteryDrawAnjinSkillWin(param1:ILayer = null)
        {
            super(param1);
            setSize(369, 603);
            this.layer = LayerManager.windowLayer3D;
            this.title = Language.getString(90416);
            return;
        }// end function

        private function setItemShow() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            if (!this._showItemVec)
            {
                this._showItemVec = new Vector.<BaseItem>;
            }
            _loc_1 = 0;
            while (_loc_1 < this._equipNum)
            {
                
                this._showItemVec[_loc_1] = UICompomentPool.getUICompoment(BaseItem);
                this._showItemVec[_loc_1].x = _loc_1 % 4 * 64 + 73;
                this._showItemVec[_loc_1].y = int(_loc_1 / 4) * 71 + 94;
                this.addChild(this._showItemVec[_loc_1]);
                _loc_2 = Cache.instance.role.entityInfo.career;
                this._showItemVec[_loc_1].itemCode = lotteryDrawConst.anjinPartsDic[_loc_2][_loc_1];
                _loc_1++;
            }
            return;
        }// end function

        private function updateEquipmentPartsState() : void
        {
            if (!this._showItemVec)
            {
                return;
            }
            var _loc_1:* = Cache.instance.role.entityInfo.career;
            var _loc_2:* = EquipmentUtil.getEquipmentSuitData(lotteryDrawConst.getSelfAnjinSuitID(), _loc_1);
            var _loc_3:* = _loc_2.parts;
            var _loc_4:int = 0;
            while (_loc_4 < this._showItemVec.length)
            {
                
                if (_loc_3[_loc_4].isActive)
                {
                    this._showItemVec[_loc_4].filters = [];
                }
                else
                {
                    this._showItemVec[_loc_4].filters = [FilterConst.colorFilter3];
                }
                _loc_4++;
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.lotteryDrawSkillShowBg, 5, 41, this));
            this._bg = UIFactory.gImageBitmap(ImagesConst.lotteryDrawSkillShowBottomBg, 0, 0, null, this.onBgLoadCompl);
            this.setItemShow();
            this.updateEquipmentPartsState();
            return;
        }// end function

        protected function onBgLoadCompl() : void
        {
            if (isDisposed)
            {
                return;
            }
            this.add3DRect();
            this.add3dBg();
            this.add3DModel();
            return;
        }// end function

        protected function add3DRect() : void
        {
            if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(7, 36 + 191 + 2, 363, 370), this);
            }
            Rect3DManager.instance.windowShowHander(null, this);
            return;
        }// end function

        protected function add3dBg() : void
        {
            if (this._rect3d)
            {
                this._rect3d.removeImg(this._img2d);
                this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, 363, 370), true);
                this._rect3d.addImg(this._img2d);
            }
            return;
        }// end function

        private function add3DModel() : void
        {
            var _loc_1:* = PlayerModelConfig.instance.getModelShowById(101000);
            var _loc_2:* = _loc_1.mesh + ".md5mesh";
            var _loc_3:* = _loc_1.bone + ".skeleton";
            var _loc_4:* = _loc_1.texture;
            var _loc_5:* = _loc_1.selfEffect;
            if (this._bodyPlayer)
            {
                this._bodyPlayer.dispose();
                this._rect3d.disposeObj3d(this._bodyPlayer);
            }
            this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
            this._bodyPlayer.enabledPool = false;
            this._bodyPlayer.load(_loc_2, _loc_3, _loc_4);
            var _loc_6:* = _loc_1.scale * 0.01;
            this._bodyPlayer.scaleZ = _loc_1.scale * 0.01;
            var _loc_6:* = _loc_6;
            this._bodyPlayer.scaleY = _loc_6;
            this._bodyPlayer.scaleX = _loc_6;
            this._bodyPlayer.play();
            this._rect3d.addObject3d(this._bodyPlayer, 183, 113 + 186);
            this._bodyPlayer.name = "LotteryDrawAnjinSkillEffectPlayer";
            this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_5, null, this._rect3d.renderList, false);
            this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
            this._effectPlayer.resetTimerContorler(this._bodyPlayer.timerContorler);
            if (this._effectPlayer.temple is TempleRole)
            {
                (this._effectPlayer.temple as TempleRole).setRoleParams(this._bodyPlayer, null, null);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._showItemVec.length)
            {
                
                this._showItemVec[_loc_2].dispose(param1);
                this._showItemVec[_loc_2] = null;
                _loc_2++;
            }
            if (this._rect3d)
            {
                this._bodyPlayer = null;
                this._effectPlayer = null;
                this._img2d = null;
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : lotteryDrawAnjinSkillWin
        {
            if (_instance == null)
            {
                _instance = new lotteryDrawAnjinSkillWin;
            }
            return _instance;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance != null && !_instance.isHide;
        }// end function

    }
}
